package com.irdstudio.apicenter.frame.core.log;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 使用Log4j来记录日志
 * 
 * @author guangming.li
 * @version 1.0
 * @date 2014-04-27
 */
public class LogbackLogger implements ILogger {

	/* 分类/模块名称 */
	private String categoryName = "";
	/* Logback的日志记录者 */
	private Logger logger = null;

	public void debug(Object message) {
		logger.error(message.toString());
	}

	public void debug(Object message, Throwable t) {
		logger.error(message.toString(), t);
	}

	public void error(Object message) {
		logger.error(message.toString());
	}

	public void error(Object message, Throwable t) {
		logger.error(message.toString(), t);
	}

	public void fatal(Object message) {
		logger.error(message.toString());
	}

	public void fatal(Object message, Throwable t) {
		logger.error(message.toString(), t);
	}

	public void info(Object message) {
		logger.info(message.toString());
	}

	public void info(Object message, Throwable t) {
		logger.info(message.toString(), t);
	}

	public void setName(String categoryName) {
		this.categoryName = categoryName;
		logger = LoggerFactory.getLogger(categoryName);
	}

	public void warn(Object message) {
		logger.warn(message.toString());
	}

	public void warn(Object message, Throwable t) {
		logger.warn(message.toString(), t);

	}

	/**
	 * 产生子级的日志记录者
	 */
	public ILogger makeSubLogger(String subCategoryName) {
		ILogger subLogger = null;
		try {
			subLogger = (ILogger) this.clone();
			subLogger.setName(this.categoryName + "-" + subCategoryName);
			return subLogger;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return subLogger;
	}
}
